<div id="main">
	<div class="hr">
		<hr />
	</div>
	<div id="example">
	<?php
	require 'conn.php';
	global $query;
	$query = "SELECT * FROM user";

	if (isset($_GET['page'])) {
		$page = intval($_GET['page']);
	}
	else
	{
		$page = 1;
	}
	$page_count = 0;
	$page_size = $psize;
	$query1 = "SELECT count(*) FROM user";
	$result = mysql_query($query1);
	$row = mysql_fetch_row($result);
	$amount = $row[0];
	if ($amount) {
		if ($amount < $page_size) {
			$page_count = 1;
		}
		if ($amount % $page_size) {
			$page_count = (int)($amount / $page_size) + 1;
		}
		else
		{
			$page_count = $amount / $page_size;
		}
	}
	else
	{
		$page_count = 0;
	}

	echo "<h2> 所有的用户 </h2>";
	echo "<blockquote>";
	echo "<p>管理员可以查看，修改和删除以下用户</p>";
	echo "</blockquote>";
	echo "<table border=1>";
	echo "<tr>";
	echo "<td>编号</td>";
	echo "<td>用户名</td>";
	echo "<td>密码</td>";
	echo "<td>昵称</td>";
	echo "<td>邮件</td>";
	echo "<td>联系电话</td>";
	echo "<td>类型</td>";
	echo "</tr>";

	if ($amount) {
		$query2 = $query." order by uid desc limit ". ($page - 1)*$page_size .", $page_size";
		$result = mysql_query($query2);
		$num = mysql_num_rows($result);
		for ($i = 0; $i < $num; $i++) {
			$row = mysql_fetch_array($result);
			$id = $row['uid'];
			$username = $row['username'];
			$password = $row['password'];
			$nickname = $row['nickname'];
			$email = $row['email'];
			$telephone = $row['telephone'];
			$type = $row['type'];
		
			echo "<tr>";
			echo "<td>".$id."</td>";
			echo "<td>".$username."</td>";
			echo "<td>".$password."</td>";
			echo "<td>".$nickname."</td>";
			echo "<td>".$email."</td>";
			echo "<td>".$telephone."</td>";
			echo "<td>".$type."</td>";
			echo "<td>";
			echo "<form action='deleteUser.php' method='post'>";
			echo "<input type='hidden' name='deleteid' value='$id'/>";
			echo "<input type='submit' value='删除'/>";
			echo "</form>";
			echo "</td>";
			echo "<td>";
			echo "<form action='resetPassword.php' method='post'>";
			echo "<input type='hidden' name='uid' value='$id'/>";
			echo "<input type='submit' value='修改'/>";
			echo "</form>";
			echo "</td>";
			echo "</tr>";
		}
		
	}

	else
	{
		echo "没有记录";
	}

	echo "</table>";

	$page_string = '';
	if ($page == 1) {
		$page_string .= '第一页|上一页';
	}
	else
	{
		$page_string .= '<a href=?page=1>第一页</a>|<a href=?page='.($page - 1).'>上一页</a>|';
	}
	if (($page == $page_count) || ($page_count == 0)) {
		$page_string .= '下一页|尾页';
	}
	else
	{
		$page_string .= '<a href=?page='.($page + 1).'>下一页</a>|<a href=?page='.$page_count.'>尾页</a>|';
	}
	echo "<br>".$page_string;
	?>

	</div>
</div>